<template>
    <div>
<van-checkbox-group v-model="result" ref="checkboxGroup">
  <van-checkbox :name="item" v-for="item in list" :key="item._id">
       <van-card
        :price="item.price"
        :desc="item.title"
        :title="item.title"
        :thumb="item.pic"
        >
        <template #footer>
            <van-stepper v-model="item.num" @click.native.stop/>
        </template>
        </van-card>
  </van-checkbox>
</van-checkbox-group>
<van-submit-bar :price="priceAll" button-text="提交订单" >
  <van-checkbox v-model="checkedIs" @click="checkAll">全选</van-checkbox>
</van-submit-bar>
       
    </div>
</template>

<script>
export default {
    name: 'cart',
    data() {
        return {
              result: [],
            list:[],
            checkedIs:false
        };
    },
    created() {
        console.log(this.$store.state.cartList);
        this.list = this.$store.state.cartList
        
    },
    methods: {
        // 点击全选
        checkAll() {    
            this.$refs.checkboxGroup.toggleAll(this.checkedIs)
            console.log(this.result);
           
        },
    },
    //组件挂载
    components: {},
    //计算属性
    computed: {
        priceAll() {
            var num = 0
            this.result.forEach(item => {
                num+=item.price*item.num*100
            });
            return num
        }
    },
    //过滤器
    filters: {},
};
</script>

<style lang="scss" scoped>
/deep/{
    .van-checkbox__label{
        width: 100%;
    }
}
</style>
